import os
import shutil

UI_PATH = "../knowledge-nebula-ui"
SERVICE_PATH = ""
TARGET_PATH = "../target"

if os.path.exists(f"{UI_PATH}/dist"):
    shutil.rmtree(f"{UI_PATH}/dist")
if os.path.exists(f"{SERVICE_PATH}/ui"):
    shutil.rmtree(f"{SERVICE_PATH}/ui")
if os.path.exists(TARGET_PATH):
    shutil.rmtree(TARGET_PATH)

os.mkdir(TARGET_PATH)

os.system(f"cd {UI_PATH} && npm run build")
shutil.copytree(f"{UI_PATH}/dist", f"{TARGET_PATH}/ui")
shutil.copy(f"assets/view_data.json", dst=f"{TARGET_PATH}/data.json")
shutil.copy(f"main.py", dst=f"{TARGET_PATH}/main.py")
